Binary Files
mIRC allows you to read and write binary files, and to modify binary variables, by using the following commands and identifiers.
/bread [-t] <filename> <S> <N> <&binvar>
This reads N bytes starting at the Sth byte position in the file and stores the result in the binary variable &binvar.
The -t switch reads data up to the next CR/LF.
/bwrite <filename> <S> [N] <text|%var|&binvar>
This writes N bytes from the specified text, %var, or &binvar, to the file starting a the Sth byte position. Any existing information at this position in the file is overwritten.
Note: If S is -1, the bytes are appended to the end of the file. If N is -1, all of the specified data is written to the file.
/bset [-t] <&binvar> <N> <asciivalue> [asciivalue ... asciivalue]
This sets the Nth byte in binary variable &binvar to the specified ascii value.
If you try to /bset a variable that doesn't exist, it is created and zero filled up to N bytes. If &binvar exists and you specify an N position beyond it's current size, it is extended to N bytes.
If you specify multiple asciivalues, they are copied to successive positions after byte position N.
The -t switch indicates that /bset should treat the values as plain text and copy them directly into &binvar.
/bunset <&binvar> [&binvar ... &binvar]
This unsets the specified list of &binvars.
/bcopy [-zc] <&binvar> <N> <&binvar> <S> <M>
This copies M bytes from position S in the second &binvar to the first &binvar at position N. This can also be used to copy overlapping parts of a &binvar to itself.
If you specify the -z switch, the bytes in the second &binvar that were copied are zero-filled after the copy.
If you specify the -c switch, the first &binvar is chopped to length N + M.
Note: If M is -1, all of the bytes from position S onwards are copied.
/breplace <&binvar> <oldvalue> <newvalue> [oldvalue newvalue...]
This replaces all matching ascii values in &binvar with new values.
/btrunc <filename> <bytes>
This truncates/extends a file to the specified length.
$bvar(&binvar,N,M)
Returns M ascii values starting from the Nth byte
Properties: text, word, nword, long, nlong
$bvar(&v,0) returns the length of the binary variable
$bvar(&v,1) returns ascii value at position N
$bvar(&v,5,3) returns ascii values from 5 to 8
$bvar(&v,5,3).text returns plain text from 5 to 8 up to the first zero character
The word, nword, long, and nlong properties return values in host or network byte order.
Notes on &binvar binary variables
Binary variables have no size limit, and are limited only by memory, can only be accessed by commands /bread and /bwrite, so they can't be printed or assigned or edited, and are automatically destroyed when a script finishes processing.
$bfind(&binvar, N, M)
Searches a &binvar for a matching value, starting from position N. M can be a character value, ie. 0 to 255, or text. The search is case-insensitive.
Properties: text
$bfind(&test, 1, mirc) finds "mirc" starting from pos 1
$bfind(&test, 5, 32) finds char 32 (a space) from pos 5
$bfind(&test, 1, 87 65 86) finds WAV from pos 1
You can use $bfind().text to force a text search if the search text is a number.
|